define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格參數配置
            Table.api.init({
                extend: {
                    index_url: 'aps/manworklog/index',
                    add_url: 'aps/manworklog/add',
                    edit_url: 'aps/manworklog/edit',
                    del_url: 'aps/manworklog/del',
                    multi_url: 'aps/manworklog/multi',
                    table: 'aps_manworklog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                showToggle: false,
                sortName: 'id',
                searchFormVisible: true,
                showToggle: false,
                showColumns: false,
                showExport: false,
                search: false,
                dblClickToEdit: false, //是否啟用雙擊編輯
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'planlog_id', title: __('Planlog_id')},
                        {field: 'man_id', title: __('Man_id')},
                        {field: 'procedure_id', title: __('Procedure_id')},
                        {field: 'procedure_startdate', title: __('Procedure_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'procedure_finishdate', title: __('Procedure_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'workhour1', title: __('Workhour1')},
                        {field: 'workhour2', title: __('Workhour2')},
                        {field: 'workhour3', title: __('Workhour3')},
                        {field: 'procedure_manhours', title: __('Procedure_manhours'), operate:'BETWEEN'},
                        {field: 'index', title: __('Index')},
                        {field: 'state', title: __('State'), searchList: {"0":__('State 0'),"1":__('State 1')}, formatter: Table.api.formatter.normal},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'planlog.id', title: __('Planlog.id')},
                        {field: 'planlog.workorder_id', title: __('Planlog.workorder_id')},
                        {field: 'planlog.procedure1_id', title: __('Planlog.procedure1_id')},
                        {field: 'planlog.procedure2_id', title: __('Planlog.procedure2_id')},
                        {field: 'planlog.procedure3_id', title: __('Planlog.procedure3_id')},
                        {field: 'planlog.procedure4_id', title: __('Planlog.procedure4_id')},
                        {field: 'planlog.procedure5_id', title: __('Planlog.procedure5_id')},
                        {field: 'planlog.procedure6_id', title: __('Planlog.procedure6_id')},
                        {field: 'planlog.procedure1_man_id', title: __('Planlog.procedure1_man_id')},
                        {field: 'planlog.procedure2_man_id', title: __('Planlog.procedure2_man_id')},
                        {field: 'planlog.procedure3_man_id', title: __('Planlog.procedure3_man_id')},
                        {field: 'planlog.procedure4_man_id', title: __('Planlog.procedure4_man_id')},
                        {field: 'planlog.procedure5_man_id', title: __('Planlog.procedure5_man_id')},
                        {field: 'planlog.procedure6_man_id', title: __('Planlog.procedure6_man_id')},
                        {field: 'planlog.procedure1_finishdate', title: __('Planlog.procedure1_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'planlog.procedure2_finishdate', title: __('Planlog.procedure2_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'planlog.procedure3_finishdate', title: __('Planlog.procedure3_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'planlog.procedure4_finishdate', title: __('Planlog.procedure4_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'planlog.procedure5_finishdate', title: __('Planlog.procedure5_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'planlog.procedure6_finishdate', title: __('Planlog.procedure6_finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'planlog.procedure1_startdate', title: __('Planlog.procedure1_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'planlog.procedure2_startdate', title: __('Planlog.procedure2_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'planlog.procedure3_startdate', title: __('Planlog.procedure3_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'planlog.procedure4_startdate', title: __('Planlog.procedure4_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'planlog.procedure5_startdate', title: __('Planlog.procedure5_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'planlog.procedure6_startdate', title: __('Planlog.procedure6_startdate'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'planlog.procedure1_manhours', title: __('Planlog.procedure1_manhours'), operate:'BETWEEN'},
                        {field: 'planlog.procedure2_manhours', title: __('Planlog.procedure2_manhours'), operate:'BETWEEN'},
                        {field: 'planlog.procedure3_manhours', title: __('Planlog.procedure3_manhours'), operate:'BETWEEN'},
                        {field: 'planlog.procedure4_manhours', title: __('Planlog.procedure4_manhours'), operate:'BETWEEN'},
                        {field: 'planlog.procedure5_manhours', title: __('Planlog.procedure5_manhours'), operate:'BETWEEN'},
                        {field: 'planlog.procedure6_manhours', title: __('Planlog.procedure6_manhours'), operate:'BETWEEN'},
                        {field: 'planlog.finishnum', title: __('Planlog.finishnum')},
                        {field: 'planlog.maxnum', title: __('Planlog.maxnum')},
                        {field: 'planlog.create_time', title: __('Planlog.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'planlog.update_time', title: __('Planlog.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'man.id', title: __('Man.id')},
                        {field: 'man.devicetype1_id', title: __('Man.devicetype1_id')},
                        {field: 'man.devicetype2_id', title: __('Man.devicetype2_id')},
                        {field: 'man.devicetype3_id', title: __('Man.devicetype3_id')},
                        {field: 'man.devicetype4_id', title: __('Man.devicetype4_id')},
                        {field: 'man.devicetype5_id', title: __('Man.devicetype5_id')},
                        {field: 'man.devicetype6_id', title: __('Man.devicetype6_id')},
                        {field: 'man.name', title: __('Man.name')},
                        {field: 'man.number', title: __('Man.number')},
                        {field: 'man.state', title: __('Man.state')},
                        {field: 'man.create_time', title: __('Man.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'man.update_time', title: __('Man.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'procedure.id', title: __('Procedure.id')},
                        {field: 'procedure.mainprocess_id', title: __('Procedure.mainprocess_id')},
                        {field: 'procedure.devicetype_id', title: __('Procedure.devicetype_id')},
                        {field: 'procedure.name', title: __('Procedure.name')},
                        {field: 'procedure.number', title: __('Procedure.number')},
                        {field: 'procedure.manhours', title: __('Procedure.manhours'), operate:'BETWEEN'},
                        {field: 'procedure.state', title: __('Procedure.state')},
                        {field: 'procedure.create_time', title: __('Procedure.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'procedure.update_time', title: __('Procedure.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 為表格綁定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});